<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<% 
 /**
  功能名称:选择教师的模态窗口
  创建时间:2010-7-13
  创建人:
**/
%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户选择</title>
	<link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
	<script src="<%=path %>/dwr/engine.js"></script>
	<script src="<%=path %>/dwr/util.js"></script>
	<script src="<%=path %>/dwr/interface/shiyueDwr.js"></script>
	<script language="javascript" src="<%=path %>/js/syAjax.js"></script>
	<script language="javascript" src="<c:url value='/js/json2.js'/>"></script>
	<script type="text/javascript">
	var paramArr=parent.giveParamArr();
	var selectType = "${param.flag}";
	if(selectType!='radio') {
		selectType='checkbox';
	}
	function load(){
      shiyueDwr.findAllGradeByYear('${applicationScope.currentYear}',1,findGradeCallBack);
    }
    //改变年级事件
    function changeGrade(gradeId){
    	if(gradeId==""){
    		return;
    	}
    	loadClass(); //载入班级
    	
    }
    function findGradeCallBack(orgMap) {
    	if(orgMap) {
	    	 delete orgMap[''];
		     DWRUtil.addOptions("grade", orgMap);
		     if("${param.gradeId}"!="")
		     {
		     	document.getElementById("grade").value="${param.gradeId}";
		     }
		     loadClass(); //载入班级
	     }
    }
	//载入班级
    function loadClass() {
    	shiyueDwr.findAllClassByYearAndStatusAndGradeId(
			'${applicationScope.currentYear}', 1, document.getElementById("grade").value, findClassCallback);
		
		function findClassCallback(map){
			document.getElementById("classId").options.length=0;
			delete map[''];
			DWRUtil.addOptions("classId", map);
			if("${param.classId}"!="")
	     	{
	     	document.getElementById("classId").value="${param.classId}";
	     	}
	     	searchStudentByClassId();
		}
    }

    function selectAll(chxName,chx){
    	var chxs=document.getElementsByName(chxName);
    	for(var i=0;i<chxs.length;i++){
    		chxs[i].checked=chx.checked;
    	}
    }
    
    
    
    

    //查询学生
    
    function searchStudentByClassId(){
    	var grade = document.getElementById('grade').value;
    	var classId = document.getElementById('classId').value;
    	//发送ajax请求，组织id，年度，获取该组织下的所有成员
		syAjax.request("post","<%=path %>/selectStudentorganizationAction.action","&grade.gradeId="+grade+"&user.userType=1&cla.classId="+classId,{success:initSuccessResult,fail:onFail,type:'plain'});
    }
    
    function initSuccessResult(response){
    	var data = JSON.parse(response);
    	var showStr="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#97B1C8\"><tr>";
    	if(data!=null){
    		if(data.length>0){
		    	for(var i=0;i<data.length;i++){
		    		if(data.length==(i+1) && (i+1)%5!=0){
		    			showStr+="<td height=\"25\" align=\"left\" valign=\"middle\" bgcolor=\"#F8F8F8\" colspan='"+(5-(i+1)%5+1)+"'>";
		    		}else{
		    			showStr+="<td height=\"25\" align=\"left\" valign=\"middle\" bgcolor=\"#F8F8F8\">";
		    		}
		    		
		    		if(paramArr.indexOf(data[i].userId)!=-1){
		    			showStr+="<input type='"+selectType+"' name=\"chkUser\" checked=\"checked\" value=\""+data[i].userId+"_"+data[i].name+"\"";
		    			<c:if test="${requestScope.ROLEID eq 'schooladmin'}">
		    			if(data[i].account=="admin"){
		    			showStr+="disabled=\"disabled\"";
		    			}
		    			</c:if>
		    			 showStr+="/>";
		    			showStr+="<font color=\"red\">"+data[i].name+"</font>";    				
		    		}else{
		    			showStr+="<input type='"+selectType+"' name=\"chkUser\" value=\""+data[i].userId+"_"+data[i].name+"\" />";
		    			showStr+=data[i].name;
		    		}
		    		
		    		
		    		showStr+="</td>";
		    		if((i+1)%5==0){
		    			showStr+="</tr><tr>";
		    		}
		    	}
	    	}else{
	    		showStr+="<td colspan=\"5\" height=\"25\" align=\"center\" valign=\"middle\" bgcolor=\"#F8F8F8\">暂无数据</td>";
	    	}
	    	showStr+="</tr></table>";
	    	document.getElementById('divUser').innerHTML=showStr;
    	}
    	
    	
    }
    
    function onFail(){
		alert("网络繁忙，请稍后再试");
	}
	
	function doReturnValue(){
		var chkArr = document.getElementsByName('chkUser');	
		var UserStr="";	
		if(chkArr!=null && chkArr.length>0){
			for(var i=0;i<chkArr.length;i++){
				if(chkArr[i].checked==true){
					UserStr += (UserStr=="")?chkArr[i].value:","+chkArr[i].value;
				}
			}
		}
		var rtn  = {};
		rtn.userIds = UserStr;
		rtn.classId = document.getElementById("classId").value;
		rtn.gradeId = document.getElementById("grade").value;
		//window.returnValue= rtn;
		//window.close();
		parent.doChooseStudent(rtn);
	}
	
	</script>

  </head>
  
  <body onload="load();" bgcolor="#ECE9D8">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="left" valign="top" bgcolor="#ECE9D8" class="border_2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left" valign="top" class="tb_10 border_2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="30" align="left" valign="top" style="white-space: nowrap;"><!-- 用户：
              <input id="UserName" name="UserName" type="text" size="15" />  -->
              &nbsp;年级：              
              <select name="select" id="grade" onchange="changeGrade()" >
              </select> 
               &nbsp;
               班级：<select name="classId" id="classId" onchange="searchStudentByClassId()">
              &nbsp;
              <input type="button" onclick="searchStudentByClassId()" name="Submit2" value="搜索" /></td>              
          </tr>
          <tr><td><c:if test="${param.flag!='radio'}"><input type="checkbox" onclick="selectAll('chkUser',this)"/><b>全选/取消</b></c:if></td></tr>
        </table>
        <div id="divUser">
  
          </div>
          </td>
      </tr>
    </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td height="1" bgcolor="#AAA899"></td>
        </tr>
        <tr>
          <td height="1" bgcolor="#FFFFFF"></td>
        </tr>
        <tr>
          <td height="35" align="center" valign="bottom"><input type="button" name="Submit" onclick="doReturnValue();" value="提 交" /></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
